<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="../js/layui/layui.js"></script>
    <link rel="stylesheet" href="../js/layui/css/layui.css"/>
</head>
<body>
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm"  onclick="openAddDialog()">新增</button>
    </div>
    <table class="layui-hide" id="schoolTable" lay-filter="schoolFilter"></table>
</body>
<script>
    var table;
    var $;
    layui.use(['table'], function() {
        table = layui.table;
        $ = layui.jquery;
        table.render({
            id:'schoolTableId',
            elem: '#schoolTable',
            fit: true,
            url: '../web/findJiaoYu', //数据接口
            cols: [
                [ //表头
                    {type:'checkbox', fixed:'left'},
                    {field:'createTime', title:'时间', align: 'center',templet:function(data){
                        return data.createTime+"—"+data.endTime;
                     }},
                    {field:'schoolName', title:'学校名称', align: 'center'},
                    {field:'tongZhao', title:'统招', align:'center',templet:function(data){
                        return data.tongZhao == 1 ? "是" : (data.tongZhao == 2 ? "否" : "");
                    }},
                    {field:'professional', title:'专业', align:'center'},
                    {fixed:'right',title: '操作',align:'center', toolbar:'#toolbar'}
                ]
            ]
        });
        table.on('tool(schoolFilter)', function(obj){
            var data = obj.data;
            if(obj.event === 'del'){
                $.post("../web/delJiaoYu",{id:data.id},function(data){
                    if(data){
                        table.reload("schoolTableId",{});
                    }else{
                        layer.alert("删除失败");
                    }
                })
            }
        })
    })

    //打开新增弹框
    function openAddDialog(){
        layer.open({
            type: 2,
            title:"新增教育经历",
            area: ['600px', '500px'],
            fixed:false,
            maxmin:true,
            content:'../page/toAddJiaoYu',
            btn:['保存'],
            btn1: function(index,layero){
                //获取子页面
                var iframeWin= window[layero.find('iframe')[0]['name']];//得到iframe页的窗口对象,执行iframe页的方法
                iframeWin.saveJiaoYu();
                table.reload("schoolTableId",{});
                layer.close(index);
            },
        });
    }

</script>
<script type="text/html" id="toolbar">
    <a class="layui-btn layui-btn-xs" lay-event="del">删除</a>
</script>
</html>